package com.wenhai.spring.aop.features.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AspectConfiguration {

    @Pointcut("execution(public * *(..))")
    public void anyPublicMethod() {}

    @Before("anyPublicMethod()")
    public void beforeAnyPublicMethod() {
        System.out.println("@Before any public method.");
//        throw new RuntimeException();
    }

    @AfterReturning("anyPublicMethod()")
    public void afterReturningAnyPublicMethod() {
        System.out.println("@AfterReturning any public method.");
    }

    @After("anyPublicMethod()")
    public void afterAnyPublicMethod() {
        System.out.println("@After any public method.");
    }



    @AfterThrowing("anyPublicMethod()")
    public void afterThrowingAnyPublicMethod() {
        System.out.println("@AfterThrowing any public method.");
    }


    @Around("anyPublicMethod()")
    public Object aroundAnyPublicMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("@Around any public method.");
        return pjp.proceed();
    }
}
